{include file="header.html"}
<body class="gr">

<div class="navBar">
	<a class="left" href="javascript:history.back()"><i class="return"></i></a>
	<div class="titleView">收货地址管理</div>
	<a class="right" href="wap.php?tpl=address.add_address">添加</a>
</div>

<div class="address-list main-padding-top">
	<div class="pullRefresh">
		<section>
			{foreach from=$data name=g item=g}
			<ul class="list tableView tableView-noLine">
				<li>
					<h1>
						<div class="name">{$g->contactman}　{$g->mobile}</div>
						<div class="address">{$g->province}{if $g->province!=$g->city} {$g->city}{/if} {$g->district} {$g->address}</div>
					</h1>
					<div class="ge-bottom ge-light"></div>
					<div class="bottomView">
						<form method="post" action="api.php?app=address&act=delete_address">
						<input type="hidden" name="gourl" value="wap.php?app=address&&act=list_address" />
						<input type="hidden" name="id" value="{$g->id}" />
						<a href="javascript:void(0)" class="btn delete"><span>删除</span></a>
						</form>
						<a href="wap.php?app=address&act=get_address&id={$g->id}" class="btn edit"><span>编辑</span></a>
						<form method="post" action="api.php?app=address&act=set_default">
						<input type="hidden" name="gourl" value="wap.php?app=address&&act=list_address" />
						<input type="hidden" name="id" value="{$g->id}" />
						<a href="javascript:void(0)" class="default">设为默认地址</a>
						</form>
					</div>
				</li>
			</ul>
			{/foreach}
		</section>
	</div>
</div>

{include file="footer.html"}
<script>
var offset = $('.pullRefresh .list > li').length;
function createHtml(g){
	var html = '<li>\
		<h1>\
			<div class="name">'+g.contactman+'　'+g.mobile+'</div>\
			<div class="address">'+(g.province+(g.province!=g.city?' '+g.city:'')+' '+g.district+' '+g.address)+'</div>\
		</h1>\
		<div class="ge-bottom ge-light"></div>\
		<div class="bottomView">\
			<form method="post" action="api.php?app=address&act=delete_address">\
			<input type="hidden" name="gourl" value="wap.php?app=address&&act=list_address" />\
			<input type="hidden" name="id" value="'+g.id+'" />\
			<a href="javascript:void(0)" class="btn delete"><span>删除</span></a>\
			</form>\
			<a href="wap.php?app=address&act=edit_address&id='+g.id+'" class="btn edit"><span>编辑</span></a>\
			<form method="post" action="api.php?app=address&act=set_default">\
			<input type="hidden" name="gourl" value="wap.php?app=address&&act=list_address" />\
			<input type="hidden" name="id" value="'+g.id+'" />\
			<a href="javascript:void(0)" class="default">设为默认地址</a>\
			</form>\
		</div>\
	</li>';
	offset++;
	return html;
}
$(function(){
	$('.address-list').height($.window().height-$('.address-list').padding().top);
	$('.pullRefresh').pullRefresh({
		header : true,
		footer : true,
		footerNoMoreText : '- END -',
		refresh : function(fn){
			var _this = this;
			offset = 0;
			$.getJSON('api.php?app=address&act=list_address', function(json){
				if(json.error!=0){ $.overloadError(json.msg);return; }
				var html = '';
				if($.isArray(json.data))for(var i=0; i<json.data.length; i++)html += createHtml(json.data[i]);
				_this.find('.list').html(html);
				fn();
			});
		},
		load : function(fn){
			var _this = this;
			$.getJSON('api.php?app=address&act=list_address', { offset:offset }, function(json){
				if(json.error!=0){ $.overloadError(json.msg);return; }
				var html = '';
				if($.isArray(json.data))for(var i=0; i<json.data.length; i++)html += createHtml(json.data[i]);
				_this.find('.list').append(html);
				fn();
			});
		}
	});
	$(document).on('click', '.delete', function(){
		$(this).parent().submit();
	});
	$(document).on('click', '.default', function(){
		$(this).parent().submit();
	});
});
</script>